import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)
        
        self.label=QLabel('Result')
        layout.addWidget(self.label)
        
        btn=QPushButton('ShowDialog(Normal)')
        btn.clicked.connect(self.ShowDialog)
        layout.addWidget(btn)

        btn=QPushButton('ShowDialog(HasReturn)')
        btn.clicked.connect(self.ShowDialogReturn)
        layout.addWidget(btn)

        btn=QPushButton('ShowDialog(HasParent)')
        btn.clicked.connect(self.ShowDialogHasParent)
        layout.addWidget(btn)

        btn=QPushButton('ShowModalDialog(NoParent Exec)')
        btn.clicked.connect(self.ShowDialogNoParent)
        layout.addWidget(btn)

        btn=QPushButton('ShowModalDialog(HasParent Exec)')
        btn.clicked.connect(self.ShowModalDialogExec)
        layout.addWidget(btn)

        btn=QPushButton('ShowModalDialog(HasParent Show)')
        btn.clicked.connect(self.ShowModalDialogShow)
        layout.addWidget(btn)

        btn=QPushButton('ShowDialog(HasParent Show)')
        btn.clicked.connect(self.ShowDialogShow)
        layout.addWidget(btn)        

        self.setLayout(layout)
    def ShowDialog(self):
        dialog=QDialog()
        dialog.setWindowTitle('Dialog(Normal)')

        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        self.label.setText(f'Result:{dialog.exec()}')
    def ShowDialogReturn(self):
        dialog=QDialog()
        dialog.setWindowTitle('Dialog(HasReturn)')

        layout=QHBoxLayout()
        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        layout.addWidget(btn)

        btn=QPushButton('Cancel',dialog)
        btn.clicked.connect(dialog.reject)
        layout.addWidget(btn)

        btn=QPushButton('Button_Custom',dialog)
        btn.clicked.connect(lambda:dialog.done(50))
        layout.addWidget(btn)

        dialog.setLayout(layout)        
        self.label.setText(f'Result:{dialog.exec()}')
    def ShowDialogHasParent(self):
        dialog=QDialog(self)
        dialog.setWindowTitle('Dialog(HasParent)')

        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        self.label.setText(f'Result:{dialog.exec()}')
    def ShowDialogNoParent(self):
        dialog=QDialog()
        dialog.setWindowTitle('Dialog(NoParent)')

        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        self.label.setText(f'Result:{dialog.exec()}')
    def ShowModalDialogExec(self):
        dialog=QDialog(self)
        dialog.setWindowTitle('ModalDialog(HasParent)')
        dialog.setWindowModality(Qt.WindowModality.WindowModal)
        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        self.label.setText(f'Result:{dialog.exec()}')
    def ShowModalDialogShow(self):
        dialog=QDialog(self)
        dialog.setWindowTitle('ModalDialog(HasParent)')
        dialog.setWindowModality(Qt.WindowModality.WindowModal)
        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        dialog.show()
        self.label.setText(f'Result:{dialog.result()}')
    def ShowDialogShow(self):
        dialog=QDialog(self)
        dialog.setWindowTitle('Dialog(HasParent)')
        
        btn=QPushButton('OK',dialog)
        btn.clicked.connect(dialog.accept)
        dialog.show()
        self.label.setText(f'Result:{dialog.result()}')
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet